package org.jb.coinche.server.statemachine.service;

import org.jb.coinche.client.guistatemachine.Message;
import org.jb.coinche.client.guistatemachine.StateService;
import org.jb.coinche.server.rooms.RoomScoped;
import org.jb.coinche.server.statemachine.StateMachine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;

@RoomScoped
public class StateServiceImpl implements StateService {

	final private static Logger logger = LoggerFactory.getLogger(StateServiceImpl.class);
	
	final private StateMachine stateMachine;
	
	/*
	 * 
	 */
	@Inject
	public StateServiceImpl( StateMachine stateMachine ) {
		this.stateMachine = stateMachine;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.jb.coinche.client.guistatemachine.StateService#sendMessage(org.jb.coinche.client.guistatemachine.Message)
	 */
	@Override
	public void sendMessage(Message msg) {
		try {
			logger.debug("Received message {}", msg );
			stateMachine.processMessage(msg);
		} catch (Throwable e) {
			e.printStackTrace();
		}

	}
	
}
